@W-20591323 workspace type auto-discovery#42
Merged
Conversation
clavery
requested changes
Jan 14, 2026
Collaborator
clavery
left a comment
There was a problem hiding this comment.
Looks good. I think the pwa/snext ones are robust. Had some comments on the SFRA and general b2c backend.
clavery
approved these changes
Jan 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR introduces Workspace Type Auto-Discovery for the B2C DX MCP server. When neither
--toolsetsnor--toolsflags are provided, the server automatically detects the project type and enables appropriate toolsets.Key features:
pwa-kit-v3,storefront-next, andcartridges(any project with.projectfiles)--working-directoryflag (global flag in SDKBaseCommand) allows explicit project path; Cursor supports${workspaceFolder}variable expansion; falls back toprocess.cwd()when not provided on MCPChanges
New Files (in
packages/b2c-tooling-sdk/src/discovery/)detector.ts-WorkspaceTypeDetectorclass anddetectWorkspaceType()convenience functionDetectOptionstypes.ts- Type definitions:ProjectType- Union type:'pwa-kit-v3' | 'storefront-next' | 'cartridges'DetectionPattern- Pattern interface withname,projectType, anddetect()functionDetectionResult- Result withprojectTypes[],matchedPatterns[],autoDiscoveredDetectOptions- Options for custom patternsutils.ts- Utility functions for pattern implementations:readPackageJson()- Parse package.json from directoryexists()- Check if file/directory existsglob()- Find files matching patternglobDirs()- Find directories matching patternindex.ts- Module exports and documentationpatterns/index.ts- Default patterns array and re-exportspatterns/pwa-kit.ts- Detects PWA Kit v3 projects (two flavors: template copy with@salesforce/pwa-kit-*packages, or extensible with@salesforce/retail-react-app/ccExtensibility)patterns/storefront-next.ts- Detects@salesforce/storefront-next-*packages in package.jsonpatterns/cartridges.ts- Detects any cartridge project by finding.projectfiles usingfindCartridges()from the SDKpatterns/sfra.ts- (Not used in DEFAULT_PATTERNS) Detects SFRA-specific patterns likecartridges/folder with controllers or templates. Available for future use or custom detection scenarios.Modified Files
packages/b2c-tooling-sdk/package.json- Added./discoveryexportpackages/b2c-dx-mcp/src/registry.ts:BASE_TOOLSETconstant (SCAPI) - always enabledPROJECT_TYPE_TOOLSETSmapping for project-specific toolsetsgetToolsetsForProjectTypes()function for union toolset selectionregisterToolsets()to useworkingDirectoryand detect multiple project types--working-directoryis not providedpackages/b2c-tooling-sdk/src/cli/base-command.ts:--working-directoryflag withSFCC_WORKING_DIRECTORYenv var support as global flagpackages/b2c-dx-mcp/src/commands/mcp.ts:packages/b2c-dx-mcp/src/utils/types.ts:workingDirectorytoStartupFlagsinterfacepackages/b2c-dx-mcp/README.md:New Test Files
packages/b2c-tooling-sdk/test/discovery/detector.test.ts- Tests forWorkspaceTypeDetectorpackages/b2c-tooling-sdk/test/discovery/utils.test.ts- Tests forreadPackageJson,exists,glob,globDirspackages/b2c-tooling-sdk/test/discovery/patterns/pwa-kit.test.ts- Tests forpwaKitV3Patternpackages/b2c-tooling-sdk/test/discovery/patterns/storefront-next.test.ts- Tests forstorefrontNextPatternpackages/b2c-tooling-sdk/test/discovery/patterns/cartridges.test.ts- Tests forcartridgesPatternpackages/b2c-tooling-sdk/test/discovery/patterns/sfra.test.ts- Tests forsfraPattern(not used in DEFAULT_PATTERNS but available for custom use)Updated Test Files
packages/b2c-dx-mcp/test/registry.test.ts- Updated to useworkingDirectorypropertypackages/b2c-dx-mcp/test/commands/mcp.test.ts- Added test for--working-directoryflagProject Type to Toolset Mapping
Base Toolset (always enabled): SCAPI - provides API discovery and custom API scaffolding
@salesforce/pwa-kit-*packages,@salesforce/retail-react-app, orccExtensibilityfield@salesforce/storefront-next-*packages in package.json.projectfiles found (viafindCartridges())Hybrid Projects: When multiple project types are detected (e.g., PWA Kit + cartridges), toolsets from all matched types are combined with the base toolset.
Test Plan
1. Auto-Discovery Basic Tests
1a. PWA Kit project detection (template copy flavor)
Setup: Open a PWA Kit project using template copy (has
@salesforce/pwa-kit-react-sdkin package.json)Config:
{ "mcpServers": { "b2c-dx": { "command": "/path/to/packages/b2c-dx-mcp/bin/dev.js", "args": ["--working-directory", "/path/to/pwa-kit-project", "--allow-non-ga-tools"] } } }Auto-discovered project types: pwa-kit-v31a-ext. PWA Kit project detection (extensible flavor)
Setup: Open a PWA Kit extensible project (has
@salesforce/retail-react-appin package.json and/orccExtensibilityfield)Auto-discovered project types: pwa-kit-v31b. Storefront Next project detection
Setup: Open a Storefront Next project (has
@salesforce/storefront-next-*in package.json)Auto-discovered project types: storefront-next1c. Cartridges project detection
Setup: Open a cartridge project (any project with
.projectfiles - SFRA, Custom API, or other cartridge types)Auto-discovered project types: cartridges1d. Unknown project fallback
Setup: Open a non-B2C project (no B2C markers)
Auto-discovered project types: none2. Working Directory Configuration Tests
2a. Cursor with
${workspaceFolder}Config:
{ "mcpServers": { "b2c-dx": { "command": "/path/to/packages/b2c-dx-mcp/bin/dev.js", "args": ["--working-directory", "${workspaceFolder}", "--allow-non-ga-tools"] } } }--working-directoryis provided, no warning is logged2b. Explicit path
Config:
{ "mcpServers": { "b2c-dx": { "command": "/path/to/packages/b2c-dx-mcp/bin/dev.js", "args": ["--working-directory", "/path/to/your/project", "--allow-non-ga-tools"] } } }2c. Environment variable
Config:
{ "mcpServers": { "b2c-dx": { "command": "/path/to/packages/b2c-dx-mcp/bin/dev.js", "args": ["--allow-non-ga-tools"], "env": { "SFCC_WORKING_DIRECTORY": "/path/to/your/project" } } } }SFCC_WORKING_DIRECTORYis set, no warning is logged2d. No working directory (fallback to cwd)
Config:
{ "mcpServers": { "b2c-dx": { "command": "/path/to/packages/b2c-dx-mcp/bin/dev.js", "args": ["--allow-non-ga-tools"] } } }3. Toolset Override Tests
3a. Explicit --toolsets disables auto-discovery
Config:
{ "mcpServers": { "b2c-dx": { "command": "/path/to/packages/b2c-dx-mcp/bin/dev.js", "args": ["--toolsets", "CARTRIDGES", "--allow-non-ga-tools"] } } }3b. Explicit --tools disables auto-discovery
Config:
{ "mcpServers": { "b2c-dx": { "command": "/path/to/packages/b2c-dx-mcp/bin/dev.js", "args": ["--tools", "scapi_discovery", "--allow-non-ga-tools"] } } }4. Claude Desktop Tests
4a. Explicit path required
Config:
{ "mcpServers": { "b2c-dx": { "command": "/path/to/packages/b2c-dx-mcp/bin/dev.js", "args": ["--working-directory", "/path/to/your/project", "--allow-non-ga-tools"] } } }4b. Variable not expanded
Config:
{ "mcpServers": { "b2c-dx": { "command": "/path/to/packages/b2c-dx-mcp/bin/dev.js", "args": ["--working-directory", "${workspaceFolder}", "--allow-non-ga-tools"] } } }${workspaceFolder}is not expanded, detection fails or uses literal pathpnpm test)pnpm run format)